<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/1 10:59
 * Modified Time: 2019/7/1 10:59
 * Version: 2.0
 */

namespace App\Modules\Service\Repositories;


use App\Models\CardTypeService;
use App\Modules\MemberCard\Validators\CardTypeServiceValidator;
use Flower\Core\Repository\Eloquent\BaseRepository;

class CardTypeServiceRepository extends BaseRepository
{
    public function model()
    {
        return CardTypeService::class;
    }

    public function validator()
    {
        return CardTypeServiceValidator::class;
    }

    public function deleteByCardTypeId($card_type_id)
    {
        return $this->deleteWhere(['type_id'=>$card_type_id]);
    }

    /**
     * 获取关联某服务的会员卡类数
     * @param $service_id
     * @return mixed
     */
    public function getCardTypeCountByService($service_id)
    {
        return $this->model->where('service_id',$service_id)
            ->groupBy('type_id')
            ->count();
    }
}